package com.zzgele.qmzb.api.bean;
import java.util.concurrent.atomic.AtomicInteger;


public class PackageCount {
    //可以发放的总数
    private AtomicInteger amount=new AtomicInteger();
    //已经发放的数量
    private AtomicInteger currentCount=new AtomicInteger();

    public int getAmount() {
        return amount.get();
    }
    public void setAmount(Integer id) {
        if(this.amount.get()==0)
            this.amount.set(id);
    }
    public int getCurrentCount() {
        return currentCount.get();
    }
    public void setCurrentCount(Integer id) {
        //避免多线程同时赋值操作
        if(currentCount.get()==0)
            this.currentCount.set(id);
    }
    public int decrementCurrentCount() {
        int b=0;
        if(currentCount.get()>0)
            return this.currentCount.decrementAndGet();
        return b;
    }
    public int compareAndIncrement(){
        int b=-1;
        if(currentCount.get()<amount.get()) {
            return this.currentCount.incrementAndGet();
        }
        return  b;
    }
}
